//
//  LiveCell.m
//  Courses
//
//  Created by xxx on 15/1/6.
//  Copyright (c) 2015年 wtf. All rights reserved.
//

#import "LiveCell.h"
#import "NSDate+WTF.h"

//"liveId": "id001",
//"beginTime": "2014-12-28 10：20：00",
//"courseId": "id001",
//"name": "name1",
//"vodId": "vod001",
//"liveState": "-1"
//课程状态 ; 0 : 正在直播，1：预告， -1：录像

@implementation LiveCell
{
    UILabel *_lblBeginTime;
    UILabel *_lblLiveState;
    UILabel *_lblName;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (!self) return self;
    
    self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    self.backgroundColor = nil;
    self.frame = AutoRectMake(0, 0, DEFAULT_WIDTH, [LiveCell liveCellHeight], WTFAutoLayoutTypeBar);
    
    _lblBeginTime = [[UILabel alloc] initWithFrame:AutoRectMake(20, 10, 80, 20, WTFAutoLayoutTypeBar)];
    _lblBeginTime.font = [UIFont fontWithName:nil size:FONT_SIZE_TITLE];
    [self.contentView addSubview:_lblBeginTime];
    
    _lblLiveState = [[UILabel alloc] initWithFrame:AutoRectMake(90, 10, 100, 20, WTFAutoLayoutTypeBar)];
    _lblLiveState.font = [UIFont fontWithName:nil size:FONT_SIZE_TITLE];
    [self.contentView addSubview:_lblLiveState];
    
    _lblName = [[UILabel alloc] initWithFrame:AutoRectMake(170, 10, 130, 20, WTFAutoLayoutTypeBar)];
    _lblName.font = [UIFont fontWithName:nil size:FONT_SIZE_TITLE];
    [self.contentView addSubview:_lblName];
    
    return self;
}

- (void)setLiveCourse:(LiveCourse *)liveCourse
{
    _lblBeginTime.text = [NSDate hourMinStringWithFullDateString:liveCourse.beginTime];
    _lblLiveState.text = [self liveStateForIntString:liveCourse.liveState];
    _lblLiveState.textColor = [self colorForIntString:liveCourse.liveState];
    _lblName.text = liveCourse.name;
}

+ (CGFloat)liveCellHeight
{
    return 40;
}

- (NSString *)liveStateForIntString:(NSString *)intString
{
    NSDictionary *stateDict = @{@"-1":@"录像", @"0":@"正在直播", @"1":@"预告"};
    return stateDict[intString];
}

- (UIColor *)colorForIntString:(NSString *)intString
{
    NSDictionary *stateColorDict = @{@"-1":[UIColor blueColor], @"0":[UIColor blackColor], @"1":[UIColor orangeColor]};
    return stateColorDict[intString];
}

@end
